Homework 4

Choose THREE of the following six problems to submit as homework. If you submit fewer than three problems, I will give you partial credit for the problems you do submit.

Each problem must be submitted as its own .cpp file. Grading for each problem is as follows:

If two or more people submit copies of the same work, every person submitting the copied work will get a 0 for the entire homework.

You must write functions outside main for each of the following problems for full credit.

    Characters

  1. Write a complete C++ program that does the following:
  2. Sample run of program:
    Enter an odd integer between 7 and 19: 7 ******* * A* * BB* * CCC* * DDDD* *EEEEE* *******
  3. Write a complete C++ program that does the following:
  4. Example main function that uses these functions:
    int main() { srand(time(0)); char arr[3][3]; fillCharArray(arr, 3, 3); printArray(arr, 3, 3); int vowelCount = countVowels(arr, 3, 3); cout << "The count of vowels in the array is " << vowelCount << endl; return 0; }

    Sample run of program:
    j u n e k t q u q The count of vowels in the array is 3
  5. Write a complete C++ program that does the following:
  6. Example main function that uses these functions. You do not need to write all the code as functions. You are only required to write the printArray function above. All other code can be written in main if you prefer.
    int main() { srand(time(0)); char arr[2][4]; int rowVowelCount[2] = {0}; int colVowelCount[4] = {0}; fillCharArray(arr, 2, 4); printArray(arr, 2, 4); // fill rowVowelCount with count of vowels per row in arr vowelsPerRow(arr, rowVowelCount, 2, 4); // fill colVowelCount with count of vowels per row in arr vowelsPerCol(arr, colVowelCount, 2, 4); printVowelRows(rowVowelCount, 2); printVowelCols(colVowelCount, 4); return 0; }

    Sample run of program:
    v j x l v e n u Row 1 contains at least one vowel. Col 1 contains at least one vowel. Col 3 contains at least one vowel.

    Strings

  7. Write a complete C++ program that does the following:
  8. Example main function that uses these functions:
    int main() { string fName, lName; int length; cout << "Please enter your first name: "; cin >> fName; cout << "Please enter your last name: "; cin >> lName; swapFirstLetters(fName, lName); cout << "Your new first name is " << fName << endl; cout << "Your new last name is " << lName << endl; length = longestString(fName, lName); // this function prints the longest string from inside the function repeatHello(length); return 0; }

    Sample run of program:
    Please enter your first name: Dave Please enter your last name: Miller Your new first name is Mave Your new last name is Diller Diller is the longest string. HelloHelloHelloHelloHelloHello
  9. Write a complete C++ program that does the following:
  10. Example main function that uses bookEndString:
    int main() { string s; int num; cout << "Enter a word with at least three letters: "; cin >> s; while(FILL IN){ FILL IN } cout << "Enter a number greater than 0: "; cin >> num; while(FILL IN) { FILL IN } bookEndString(s, num); cout << "The modified word is: " << s << endl; return 0; }

    Sample run of program:
    Enter a word with at least three letters: hi Invalid input! Enter a word with at least three letters: hello Enter a number greater than 0: 0 Invalid input! Enter a number greater than 0: 3 The modified word is: ZZZhelloZZZ

    Another sample run of program:
    Enter a word with at least three letters: shoes Enter a number greater than 0: 4 The modified word is: ssssshoesssss
  11. Write a complete C++ program that does the following:
  12. Example main function that uses these functions:
    int main() { string words[5], prefixes[5]; cout << "Enter five words: "; readInput(words, 5); getPrefixes(words, prefixes, 5); string s = concatenateStrings(prefixes, 5); cout << "Concatenated string is " << s << endl; return 0; }

    Sample run of program:
    Enter five words: bird cat dog horse ox Concatenated string is bircatdoghorox